// pages/help/agree.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        time_index:0,
        car_index:0,
        type_index:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //this.getAgree();
        this.setData({
            platform:app.globalData.platform,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.domain
          })
    },
    goBack(){
        wx.navigateBack();
      },
    
    goto:function(e){
      console.log(e);
      var url=e.currentTarget.dataset.url;
      var index=e.currentTarget.dataset.index;
      app.goto(url,index)
  },
  stepOrder(){
    var data = this.data;
    var car_id = data.car_id;
    var plate = data.plate;
    var wash_id = data.wash_id;
    var wash_name = data.wash_name;
     //console.log(car_id);
     if(car_id == undefined){
       app.showModals('请选择车辆','#','#');
     }else if(wash_id == undefined){
       app.showModals('请选择服务类型','#','#');
     }else{
       var url='stepOrder?car_id='+car_id+'&plate='+plate+'&wash_id='+wash_id+'&wash_name='+wash_name
       app.goto(url,'#');
     }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate();
     if(month<10){
      month = "0"+month;
     }
    var now = year+'-'+month+'-'+day;
    console.log('nowshow')
   
    console.log(now);
    this.setData({
      date:now,
      now:now
    })
    this.getWashOrderSelect();
  },
  getWashOrderSelect(){
    let that = this;
     var open = wx.getStorageSync('open')
    console.log('----getCates-- end---')
   wx.request({
     url: app.globalData.domain+'wechat/wash/getWashOrderSelect',
     data:{'from':"3",open_id:open.id},
    success:res => {
      console.log(res)   
      let data = res.data;  
      var car = data.car;
      var number = car.length;

      var car_array= [];
      var cars = [];
      car_array.push('请选择');
      cars.push('');
      car.forEach(ele=>{
        car_array.push(ele.plate);
        cars.push(ele);
      })
      var type = data.type;
      var type_array= [];
      var types = [];
      type_array.push('请选择');
      types.push('');
      type.forEach(ele=>{
        type_array.push(ele.name +' '+ele.price );
        types.push(ele);
      })
      this.setData({
        car:cars,
        car_array:car_array,
        type:types,
        type_array:type_array,
        timeSelect:data.time,
        number:number
      })
      if(number==0){
        that.showModals('请先添加车辆','../car/add','#');
      }
    }
  })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },
    bindDateChange: function (e) {
      console.log('picker发送选择改变，携带值为', e.detail.value)
      this.setData({
        date: e.detail.value
      })
    },
    bindTimeChange(e){
        var index = e.detail.value;
        this.setData({
            time_index:index
        })
    },
    bindCarChange(e){
      var index = e.detail.value;
      this.setData({
          car_index:index
      })
  },
  bindTypeChange(e){
    var index = e.detail.value;
    this.setData({
        type_index:index
    })
},
inputDesc(e){
  var value = e.detail.value;
  this.setData({
    desc:value
  })
},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})